#include <stdio.h>
#include <stdlib.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrCoreVector.h>
#include "../macro.h"


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstHMirror(dtype)						\
  									\
  dtype rawsrc[]={0,0,0,						\
		  0,1,1,						\
		  0,1,1};						\
									\
  dtype rawref[]={0,0,0,						\
		  1,1,0,						\
		  1,1,0};						\
									\
  FLGR_Data2D *imgsrc;							\
  FLGR_Data2D *imghmir;							\
  FLGR_Data2D *imghmir2;						\
  FLGR_Data2D *imgref;							\
									\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir2 = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imghmir2,rawsrc);				\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_mirror_horizontal(imghmir,imgsrc);				\
  check_and_display_data2d(imgref,imghmir,ret);				\
									\
  flgr2d_mirror_horizontal_hmorph(imghmir2);				\
  check_and_display_data2d(imgref,imghmir2,ret);			\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imghmir);						\
  flgr2d_destroy(imghmir2);						\
									\
  return 2


int testhMirror_fgBIT(void) {
  tstHMirror(fgBIT);
}
int testhMirror_fgUINT8(void) {
  tstHMirror(fgUINT8);
}
int testhMirror_fgUINT16(void) {
  tstHMirror(fgUINT16);
}
int testhMirror_fgUINT32(void) {
  tstHMirror(fgUINT32);
}
int testhMirror_fgINT8(void) {
  tstHMirror(fgINT8);
}
int testhMirror_fgINT16(void) {
  tstHMirror(fgINT16);
}
int testhMirror_fgINT32(void) {
  tstHMirror(fgINT32);
}
int testhMirror_fgFLOAT32(void) {
  tstHMirror(fgFLOAT32);
}
int testhMirror_fgFLOAT64(void) {
  tstHMirror(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstHMirror_spp5(dtype)						\
  									\
  dtype rawsrc[]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,			\
		  0,0,0,0,0, 1,1,1,1,1, 1,1,0,1,1,			\
		  0,0,0,0,0, 1,1,1,1,0, 1,0,1,1,1};			\
									\
  dtype rawref[]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,			\
		  1,1,0,1,1, 1,1,1,1,1, 0,0,0,0,0,			\
		  1,0,1,1,1, 1,1,1,1,0, 0,0,0,0,0};			\
									\
  FLGR_Data2D *imgsrc;							\
  FLGR_Data2D *imghmir;							\
  FLGR_Data2D *imghmir2;						\
  FLGR_Data2D *imgref;							\
									\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(3,3,5,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(3,3,5,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir = flgr2d_create_##dtype(3,3,5,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir2 = flgr2d_create_##dtype(3,3,5,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imghmir2,rawsrc);				\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_mirror_horizontal(imghmir,imgsrc);				\
  check_and_display_data2d(imgref,imghmir,ret);				\
									\
  flgr2d_mirror_horizontal_hmorph(imghmir2);				\
  check_and_display_data2d(imgref,imghmir2,ret);			\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imghmir);						\
  flgr2d_destroy(imghmir2);						\
									\
  return 2


int testhMirror_spp5_fgBIT(void) {
  tstHMirror_spp5(fgBIT);
}
int testhMirror_spp5_fgUINT8(void) {
  tstHMirror_spp5(fgUINT8);
}
int testhMirror_spp5_fgUINT16(void) {
  tstHMirror_spp5(fgUINT16);
}
int testhMirror_spp5_fgUINT32(void) {
  tstHMirror_spp5(fgUINT32);
}
int testhMirror_spp5_fgINT8(void) {
  tstHMirror_spp5(fgINT8);
}
int testhMirror_spp5_fgINT16(void) {
  tstHMirror_spp5(fgINT16);
}
int testhMirror_spp5_fgINT32(void) {
  tstHMirror_spp5(fgINT32);
}
int testhMirror_spp5_fgFLOAT32(void) {
  tstHMirror_spp5(fgFLOAT32);
}
int testhMirror_spp5_fgFLOAT64(void) {
  tstHMirror_spp5(fgFLOAT64);
}




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstVMirror(dtype)						\
  									\
  dtype rawsrc[]={0,0,0,						\
		  0,1,1,						\
		  0,1,1};						\
									\
  dtype rawref[]={0,1,1,						\
		  0,1,1,						\
		  0,0,0};						\
									\
  FLGR_Data2D *imgsrc;							\
  FLGR_Data2D *imghmir;							\
  FLGR_Data2D *imghmir2;						\
  FLGR_Data2D *imgref;							\
									\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir2 = flgr2d_create_##dtype(3,3,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imghmir2,rawsrc);				\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_mirror_vertical(imghmir,imgsrc);				\
  check_and_display_data2d(imgref,imghmir,ret);				\
									\
  flgr2d_mirror_vertical_hmorph(imghmir2);				\
  check_and_display_data2d(imgref,imghmir2,ret);			\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imghmir);						\
  flgr2d_destroy(imghmir2);						\
									\
  return 2


int testvMirror_fgBIT(void) {
  tstVMirror(fgBIT);
}
int testvMirror_fgUINT8(void) {
  tstVMirror(fgUINT8);
}
int testvMirror_fgUINT16(void) {
  tstVMirror(fgUINT16);
}
int testvMirror_fgUINT32(void) {
  tstVMirror(fgUINT32);
}
int testvMirror_fgINT8(void) {
  tstVMirror(fgINT8);
}
int testvMirror_fgINT16(void) {
  tstVMirror(fgINT16);
}
int testvMirror_fgINT32(void) {
  tstVMirror(fgINT32);
}
int testvMirror_fgFLOAT32(void) {
  tstVMirror(fgFLOAT32);
}
int testvMirror_fgFLOAT64(void) {
  tstVMirror(fgFLOAT64);
}



/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstVMirror_spp6(dtype)						\
  									\
  dtype rawsrc[]={0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0,		\
		  0,0,0,0,0,0, 1,1,1,1,1,1, 1,1,1,0,1,1,		\
		  0,0,0,0,0,0, 0,1,1,1,1,1, 1,1,1,1,1,1};		\
									\
  dtype rawref[]={0,0,0,0,0,0, 0,1,1,1,1,1, 1,1,1,1,1,1,		\
		  0,0,0,0,0,0, 1,1,1,1,1,1, 1,1,1,0,1,1,		\
		  0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0};		\
									\
  FLGR_Data2D *imgsrc;							\
  FLGR_Data2D *imghmir;							\
  FLGR_Data2D *imghmir2;						\
  FLGR_Data2D *imgref;							\
									\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(3,3,6,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(3,3,6,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir = flgr2d_create_##dtype(3,3,6,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imghmir2 = flgr2d_create_##dtype(3,3,6,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imghmir2,rawsrc);				\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_mirror_vertical(imghmir,imgsrc);				\
  check_and_display_data2d(imgref,imghmir,ret);				\
									\
  flgr2d_mirror_vertical_hmorph(imghmir2);				\
  check_and_display_data2d(imgref,imghmir2,ret);			\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imghmir);						\
  flgr2d_destroy(imghmir2);						\
									\
  return 2


int testvMirror_spp6_fgBIT(void) {
  tstVMirror_spp6(fgBIT);
}
int testvMirror_spp6_fgUINT8(void) {
  tstVMirror_spp6(fgUINT8);
}
int testvMirror_spp6_fgUINT16(void) {
  tstVMirror_spp6(fgUINT16);
}
int testvMirror_spp6_fgUINT32(void) {
  tstVMirror_spp6(fgUINT32);
}
int testvMirror_spp6_fgINT8(void) {
  tstVMirror_spp6(fgINT8);
}
int testvMirror_spp6_fgINT16(void) {
  tstVMirror_spp6(fgINT16);
}
int testvMirror_spp6_fgINT32(void) {
  tstVMirror_spp6(fgINT32);
}
int testvMirror_spp6_fgFLOAT32(void) {
  tstVMirror_spp6(fgFLOAT32);
}
int testvMirror_spp6_fgFLOAT64(void) {
  tstVMirror_spp6(fgFLOAT64);
}





/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstCopy(dtype)							\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  FLGR_Data2D *imgsrc;							\
  FLGR_Data2D *imgU8,*imgU16,*imgU32,*imgS8,*imgS16,*imgS32;		\
  FLGR_Data2D *imgF32,*imgF64,*imgdest;					\
									\
  FLGR_Ret ret;								\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgdest = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgU8   = flgr2d_create_pixmap(8,10,1,FLGR_UINT8);			\
  imgU16  = flgr2d_create_pixmap(8,10,1,FLGR_UINT16);			\
  imgU32  = flgr2d_create_pixmap(8,10,1,FLGR_UINT32);			\
  imgS8   = flgr2d_create_pixmap(8,10,1,FLGR_INT8);			\
  imgS16  = flgr2d_create_pixmap(8,10,1,FLGR_INT16);			\
  imgS32  = flgr2d_create_pixmap(8,10,1,FLGR_INT32);			\
  imgF32  = flgr2d_create_pixmap(8,10,1,FLGR_FLOAT32);			\
  imgF64  = flgr2d_create_pixmap(8,10,1,FLGR_FLOAT64);			\
									\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
									\
									\
									\
  flgr2d_copy(imgU8,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgU8);					\
  printf(#dtype " -> fgUINT8 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgU16,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgU16);					\
  printf(#dtype " -> fgUINT16 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgU32,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgU32);					\
  printf(#dtype " -> fgUINT32 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgS8,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgS8);					\
  printf(#dtype " -> fgINT8 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgS16,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgS16);					\
  printf(#dtype " -> fgINT16 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgS32,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgS32);					\
  printf(#dtype " -> fgINT32 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgF32,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgF32);					\
  printf(#dtype " -> fgFLOAT32 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  flgr2d_copy(imgF64,imgsrc);						\
  ret = flgr2d_copy(imgdest,imgF64);					\
  printf(#dtype " -> fgFLOAT64 : ");					\
  check_and_display_data2d(imgsrc,imgdest,ret);				\
									\
  printf("\n");								\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgdest);						\
  flgr2d_destroy(imgU8);						\
  flgr2d_destroy(imgU16);						\
  flgr2d_destroy(imgU32);						\
  flgr2d_destroy(imgS8);						\
  flgr2d_destroy(imgS16);						\
  flgr2d_destroy(imgS32);						\
  flgr2d_destroy(imgF32);						\
  flgr2d_destroy(imgF64);						\
									\
  return 8


int testcopy_fgUINT8(void) {
  tstCopy(fgUINT8);
}
int testcopy_fgUINT16(void) {
  tstCopy(fgUINT16);
}
int testcopy_fgUINT32(void) {
  tstCopy(fgUINT32);
}
int testcopy_fgINT8(void) {
  tstCopy(fgINT8);
}
int testcopy_fgINT16(void) {
  tstCopy(fgINT16);
}
int testcopy_fgINT32(void) {
  tstCopy(fgINT32);
}
int testcopy_fgFLOAT32(void) {
  tstCopy(fgFLOAT32);
}
int testcopy_fgFLOAT64(void) {
  tstCopy(fgFLOAT64);
}







/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstCopyBit(dtype)						\
									\
  dtype rawsrc[]={  0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,127,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0, 33, 66,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0, 98,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  0, 80,  0,  0,  0,		\
		    94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  dtype rawref[]={  0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  1,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  1,  0,  0,  0,  0,		\
		    0,  0,  0,  0,  0,  0,  1,  0,  0,  0,		\
		    1,  1,  1,  1,  1,  1,  1,  1,  1,  1};		\
									\
									\
  FLGR_Data2D *imgsrc,*imgref;						\
  FLGR_Data2D *imgdest,*imgbit;						\
  FLGR_Ret ret;								\
									\
  imgsrc    = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref    = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgbit    = flgr2d_create_pixmap(8,10,1,FLGR_BIT);			\
  imgdest   = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret = flgr2d_copy(imgbit,imgsrc);					\
  check_ret(ret,FLGR_RET_OK);						\
									\
  ret = flgr2d_copy(imgdest,imgbit);					\
  check_and_display_data2d(imgref,imgdest,ret);				\
									\
  printf("\n");								\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgdest);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(imgbit);						\
									\
  return 1


int testcopybit_fgUINT8(void) {
  tstCopyBit(fgUINT8);
}
int testcopybit_fgUINT16(void) {
  tstCopyBit(fgUINT16);
}
int testcopybit_fgUINT32(void) {
  tstCopyBit(fgUINT32);
}
int testcopybit_fgINT8(void) {
  tstCopyBit(fgINT8);
}
int testcopybit_fgINT16(void) {
  tstCopyBit(fgINT16);
}
int testcopybit_fgINT32(void) {
  tstCopyBit(fgINT32);
}
int testcopybit_fgFLOAT32(void) {
  tstCopyBit(fgFLOAT32);
}
int testcopybit_fgFLOAT64(void) {
  tstCopyBit(fgFLOAT64);
}


